<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<?php //set $_SESSION['perm'] to correct value
	$_SESSION[perm] = $_REQUEST[perm];
?>
Is this person eligible? (>0000) <?php print checkQualified("0000"); ?><br />
Is this person qualified as a trainee? (0001) <?php print checkQualified("0001"); ?><br />
Is this person qualified as a bus washer? (0002) <?php print checkQualified("0002"); ?><br />
Is this person qualified as a driver? (0004) <?php print checkQualified("0004"); ?><br />
Is this person qualified as a storrs/mansfield? (0010) <?php print checkQualified("0010"); ?><br />
Is this person qualified as a Buckland Driver? (0020) <?php print checkQualified("0020"); ?><br />
Is this person qualified as a PMer? (0100) <?php print checkQualified("0100"); ?><br />
Is this person qualified as a trainer? (0200) <?php print checkQualified("0200"); ?><br />
Is this person qualified as a Dispatcher? (0400) <?php print checkQualified("0400"); ?><br />
Is this person qualified as a AM? (1000) <?php print checkQualified("1000"); ?><br />
Is this person qualified as a manager? (2000) <?php print checkQualified("2000"); ?><br />
Is this person qualified as an admin? (4000) <?php print checkQualified("4000"); ?><br />

</body>
</html>

<?php

function checkQualified($required) {
	$req_piece = preg_split('//', $required,-1,PREG_SPLIT_NO_EMPTY);
	$cur_piece = preg_split('//', $_SESSION[perm],-1,PREG_SPLIT_NO_EMPTY);
//	print_r($req_piece);
//	print_r($cur_piece);
	if($required >= 1000) {
		//check for ams and admins here
		if(($req_piece[0] == 1) and (($cur_piece[0] == 1) or ($cur_piece[0] == 3) or ($cur_piece[0] == 5) or ($cur_piece[0] == 7))) {
			$qualified = true;
		} else if(($req_piece[0] == 2) and (($cur_piece[0] == 2) or ($cur_piece[0] == 3) or ($cur_piece[0] == 6) or ($cur_piece[0] == 7))) {
			$qualified = true;
		} else if(($req_piece[0] == 4) and (($cur_piece[0] == 4) or ($cur_piece[0] == 5) or ($cur_piece[0] == 6) or ($cur_piece[0] == 7))) {
			$qualified = true;
		} else {
			$qualified = false;
		}		
	} else if ($required >= 100) {
		//check for dispatch, pm and training
		if(($req_piece[1] == 1) and (($cur_piece[1] == 1) or ($cur_piece[1] == 3) or ($cur_piece[1] == 5) or ($cur_piece[1] == 7))) {
			$qualified = true;
		} else if(($req_piece[1] == 2) and (($cur_piece[1] == 2) or ($cur_piece[1] == 3) or ($cur_piece[1] == 6) or ($cur_piece[1] == 7))) {
			$qualified = true;
		} else if(($req_piece[1] == 4) and (($cur_piece[1] == 4) or ($cur_piece[1] == 5) or ($cur_piece[1] == 6) or ($cur_piece[1] == 7))) {
			$qualified = true;
		} else {
			$qualified = false;
		}		
	} else if ($required >= 10) {
		//check for buckland and storrs/mansfield
		if(($req_piece[2] == 1) and (($cur_piece[2] == 1) or ($cur_piece[2] == 3) or ($cur_piece[2] == 5) or ($cur_piece[2] == 7))) {
			$qualified = true;
		} else if(($req_piece[2] == 2) and (($cur_piece[2] == 2) or ($cur_piece[2] == 3) or ($cur_piece[2] == 6) or ($cur_piece[2] == 7))) {
			$qualified = true;
		} else if(($req_piece[2] == 4) and (($cur_piece[2] == 4) or ($cur_piece[2] == 5) or ($cur_piece[2] == 6) or ($cur_piece[2] == 7))) {
			$qualified = true;
		} else {
			$qualified = false;
		}		
	} else if ($required >= 1) {
		//check for trainee, buswash and shuttle
		if(($req_piece[3] == 1) and (($cur_piece[3] == 1) or ($cur_piece[3] == 3) or ($cur_piece[3] == 5) or ($cur_piece[3] == 7))) {
			$qualified = true;
		} else if(($req_piece[3] == 2) and (($cur_piece[3] == 2) or ($cur_piece[3] == 3) or ($cur_piece[3] == 6) or ($cur_piece[3] == 7))) {
			$qualified = true;
		} else if(($req_piece[3] == 4) and (($cur_piece[3] == 4) or ($cur_piece[3] == 5) or ($cur_piece[3] == 6) or ($cur_piece[3] == 7))) {
			$qualified = true;
		} else {
			$qualified = false;
		}
	} else {
		//check if the person is eligible to sign up
		if($cur_piece[3] > 0) {
			$qualified = true;
		} else {
			$qualified = false;
		}
	}
	if($qualified) {
		return "YES";
	} else {
		return "NO";
	}
}

?>